package svn;

import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
import org.tmatesoft.svn.core.wc.ISVNOptions;
import org.tmatesoft.svn.core.wc.ISVNEventHandler;
import org.tmatesoft.svn.core.wc.SVNClientManager;
import org.tmatesoft.svn.core.wc.SVNCommitClient;
import org.tmatesoft.svn.core.wc.SVNWCClient;
import org.tmatesoft.svn.core.wc.SVNWCUtil;

import java.io.File;

public class SVNCommitExample {
    public static void main(String[] args) {
        // 初始化SVN库
        setupLibrary();

        // 本地文件路径
        File fileToAdd = new File("C:\\Datas\\E9\\客户分支\\S深圳市卡司通展览股份");
        // SVN服务器URL
        String svnUrl = "svn://hostname/path/to/svn/repository"; // 替换为您的SVN服务器URL

        // 设置身份验证信息，如果需要的话
        ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager("shxl2021", "ff8d7o0rmc2j7");

        try {
            SVNURL svnRepositoryURL = SVNURL.parseURIDecoded(svnUrl);

            // 创建SVNClientManager实例
            SVNClientManager clientManager = SVNClientManager.newInstance((ISVNOptions) null, authManager);

            // 创建SVNWCClient实例
            SVNWCClient wcClient = clientManager.getWCClient();

            // 将文件添加到版本控制
            wcClient.doAdd(fileToAdd, false, false, false, SVNDepth.INFINITY, false, false);

            // 创建SVNCommitClient实例
            SVNCommitClient commitClient = clientManager.getCommitClient();

            // 提交文件到SVN服务器
           // commitClient.doCommit(new File[]{fileToAdd}, true, "2310已知问题统计提交", null, null, false, false, SVNDepth.INFINITY);
        } catch (SVNException e) {
            e.printStackTrace();
        }
    }

    private static void setupLibrary() {
        // 初始化SVN库
        DAVRepositoryFactory.setup();
        SVNRepositoryFactoryImpl.setup();
        FSRepositoryFactory.setup();
    }
}
